package fauxman.states;

import fauxman.DynamicElements.Ghost;
import fauxman.model.WorldModel;

public class LeavingHouseState extends GhostHouseState{
	private static LeavingHouseState instance;
	private static int[] leftTarget = {12,11};
	private static int[] outTarget = {13,11};
	private static int[] rightTarget = {14,11};
	
	private LeavingHouseState(){
	}
	
	public static LeavingHouseState getInstance(){
		if (instance==null)
			instance = new LeavingHouseState();
		return instance;
	}
	
	//Vulnerable Ghost doesnt have a target since it wanders aimlessly
	public int[] getTarget(WorldModel model, Ghost g) {
		//TODO: LEFT or RIGHT
		if(g.getLookAhead().x == outTarget[0] && g.getLookAhead().y == outTarget[1]){
			return (g.getInHouseStateChanges() >= 1) ? rightTarget : leftTarget;
		}
		return outTarget;
	}
	@Override
	public void reactToCurrentDiscretePosition(WorldModel model, Ghost g){
		if((g.getDiscretePosition().x == leftTarget[0] && g.getDiscretePosition().y == leftTarget[1]) || (g.getDiscretePosition().x == rightTarget[0] && g.getDiscretePosition().y == rightTarget[1])){
			System.out.println("Ghost \""+ g + "\" changing to NormalGhostState");
			g.setInHouseStateChanges(0);
			g.hitGhostHouseTarget(model.getGhostsCurrentState(g));
		}
	}
}
